<script setup lang="ts">
import { ref } from 'vue'

const activeIndex = ref(0)
const arr = ['首页', '分类', '消息', '我的']
const changeIndex = (index) => {
  activeIndex.value = index
}
</script>


<template>
  <div class="box">
    <span
      v-for="(item, index) in arr"
      :key="index"
      :class="{ active: activeIndex === index }"
      @click="changeIndex(index)"
      >{{ item }}</span
    >
  </div>
</template>

<style>
.box {
  display: flex;
}

.box span {
  width: 100px;
  height: 60px;
  text-align: center;
  line-height: 60px;
  margin-right: 10px;
}

.active {
  background-color: red;
}
</style>